const defaultState = {
  inputValue: '',
  list: []
}

export default (state = defaultState, action) => {
  // 拷贝数据  修改数据  返回确定数据
  const newState = JSON.parse(JSON.stringify(state));
  if (action.type === 'change_input_value') {
    newState.inputValue = action.value;
  }

  if (action.type === 'add_btn_click') {
    newState.list = [...newState.list, newState.inputValue]
    newState.inputValue = ''
  }

  if (action.type === 'delete_list_item') {
    newState.list.splice(action.index, 1)  
  }

  if (action.type === 'init_todolist_data') {
    newState.list = action.data
  }
  

  return newState;
}